using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using mvcincode.Auth.Requirement;

namespace mvcincode.Auth.Handler;


public class Show404Handler : AuthorizationHandler<Show404Requirement>
{
    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, Show404Requirement requirement)
    {
        // var claim = context.User.FindFirst(claim => claim.Type == ClaimTypes.Name && claim.Value == "Alan");
        // if (claim == null)
        //     return Task.CompletedTask;

        bool v = context.User.HasClaim(claim => claim.Type == ClaimTypes.Name && claim.Value == "Alan");
        if (!v)
            return Task.CompletedTask;
            
        context.Succeed(requirement);
        return Task.CompletedTask;
    }
}